<template>
    <div class="flower-service-container">

      
      <!-- 将分类部分改为轮播图 -->
      <div class="banner-carousel">
        <el-carousel :interval="4000" height="400px" indicator-position="outside">
          <el-carousel-item v-for="(banner, index) in banners" :key="index">
            <img :src="banner.image" :alt="banner.title" class="carousel-image">
            <div class="carousel-content">
              <h3>{{ banner.title }}</h3>
              <p>{{ banner.subtitle }}</p>
              <el-button type="primary" round>{{ banner.buttontext }}</el-button>
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>
      
      <!-- 商品推荐部分保持不变 -->
      <div class="today-recommend">
        <h3 class="section-title">今日推荐</h3>
        <el-row :gutter="20">
          <el-col :span="8" v-for="(product, index) in jinRiProducts" :key="index">
            <el-card class="product-card" :body-style="{ padding: '0px' }">
                <div @click="goToDetail(product)">
                    <div class="product-image" :style="{ backgroundImage: 'url(' + product.image + ')' }"></div>
                    <div class="product-info">
                      <h4>{{ product.name }}</h4>
                      <p class="description">{{ product.description }}</p>
                      <div class="price">
                        <span class="current-price">￥{{ product.price }}</span>
                        <span class="original-price" v-if="product.originalPrice">¥{{ product.originalPrice }}</span>
                      </div>
                    </div>
                </div>
            </el-card>
          </el-col>
        </el-row>
      </div>

       <!-- 商品推荐部分保持不变 -->
       <div class="today-recommend">
        <h3 class="section-title">新品上市</h3>
        <el-row :gutter="20">
          <el-col :span="8" v-for="(product, index) in xinPinProducts" :key="index">
            <el-card class="product-card" :body-style="{ padding: '0px' }" >
                <div @click="goToDetail(product.id)">
                    <div class="product-image" :style="{ backgroundImage: 'url(' + product.image + ')' }"></div>
                    <div class="product-info">
                      <h4>{{ product.name }}</h4>
                      <p class="description">{{ product.description }}</p>
                      <div class="price">
                        <span class="current-price">￥{{ product.price }}</span>
                        <span class="original-price" v-if="product.originalPrice">¥{{ product.originalPrice }}</span>
                      </div>
                    </div>
                </div>
              
            </el-card>
          </el-col>
        </el-row>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        content: '',
        // 轮播图数据
        banners: [
      ],
      // 文旅产品数据
      jinRiProducts: [],
      xinPinProducts: [],
      };
    },
    
    methods: {
      searchContent() {
        // 搜索功能实现
        console.log('搜索内容:', this.content);
      },
      
      loadData() {
        try {
          this.$axios.get("api/banner/queryBanner").then(response => {
            if (response.data.code == 200) {
              this.banners = response.data.data; // 假设数据在data字段
            } else {
              console.error('请求成功但状态非200:', response.code);
              this.$message.error(response.msg || '获取数据失败');
            }
          });
        }catch (error) {
          console.error('请求失败:', error);
          this.$message.error('网络请求异常');
        }
      
      },
      loadJinRiProducts() {
        try {
            this.$axios.get("api/product/queryJinRiProduct").then(response => {
                if (response.data.code == 200) {
                    this.jinRiProducts = response.data.data; // 假设数据在data字段
                } else {
                    console.error('请求成功但状态非200:', response.code);
                    this.$message.error(response.msg || '获取数据失败');
                }
            });
        }
        catch (error) {
            console.error('请求失败:', error);
            this.$message.error('网络请求异常');
        }
      },
      loadXinPinProducts() {
        try {
            this.$axios.get("api/product/queryXinPinProduct").then(response => {
                if (response.data.code == 200) {
                    this.xinPinProducts = response.data.data; // 假设数据在data字段
                } else {
                    console.error('请求成功但状态非200:', response.code);
                    this.$message.error(response.msg || '获取数据失败');
                }
            });
        }
        catch (error) {
            console.error('请求失败:', error);
            this.$message.error('网络请求异常');
        }
      },
      goToDetail(product) {
        
        this.$router.push({path: 'ProductDetail',query: { 'product': product }});
      }
    },
    mounted() {
        this.loadData();
        this.loadJinRiProducts();
        this.loadXinPinProducts();
    },
    
  };
  </script>
  
  <style scoped>
  .flower-service-container {
    padding: 20px;
    background-color: #f4f7fa;
    font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  }
  
  .header {
    text-align: center;
    margin-bottom: 30px;
  }
  
  /* 新增轮播图样式 */
  .banner-carousel {
    margin-bottom: 40px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  }
  
  .carousel-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  
  .carousel-content {
    position: absolute;
    top: 50%;
    left: 10%;
    transform: translateY(-50%);
    color: #fff;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
  }
  
  .carousel-content h3 {
    font-size: 36px;
    margin-bottom: 15px;
  }
  
  .carousel-content p {
    font-size: 18px;
    margin-bottom: 20px;
  }
  
  /* 今日推荐标题样式 */
  .section-title {
    color: #333;
    font-size: 20px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
  }
  
  /* 原有商品卡片样式保持不变 */
  .today-recommend {
    background-color: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
  
  .product-card {
    margin-bottom: 20px;
    border-radius: 8px;
    overflow: hidden;
  }
  
  .product-image {
    height: 180px;
    background-size: cover;
    background-position: center;
  }
  
  .product-info {
    padding: 15px;
  }
  
  .product-info h4 {
    color: #333;
    font-size: 16px;
    margin: 0 0 10px 0;
  }
  
  .description {
    color: #666;
    font-size: 12px;
    height: 36px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin-bottom: 15px;
  }
  
  .price {
    display: flex;
    align-items: center;
  }
  
  .current-price {
    color: #f56c6c;
    font-size: 18px;
    font-weight: bold;
    margin-right: 10px;
  }
  
  .original-price {
    color: #999;
    font-size: 14px;
    text-decoration: line-through;
  }
  </style>